<?php

class PublishingManager extends Manager
{
	const TABLE_NAME = 'wydawnictwa';
	const OBJECT_NAME = 'Publishing';

	public function getByName($name)
	{
		$select = $this->_db->select()->from(self::TABLE_NAME)
					->where('name = ?', $name);
		$result = $this->_db->fetchRow($select);
		return $this->_createObject(self::OBJECT_NAME, $result);
	}

	public function getAll()
	{
		$select = $this->_db->select()->from(self::TABLE_NAME)->order('nazwa ASC');
		return $this->_fetchCollection(self::OBJECT_NAME, $select);
	}

	public function getByEditionIsbn($isbn)
	{
		$select = $this->_db->select()->from(self::TABLE_NAME, self::TABLE_NAME . '.*')
					->join(EditionManager::TABLE_NAME, 
						EditionManager::TABLE_NAME . '.idWydawnictwa = ' . self::TABLE_NAME . '.nazwa', '')
					->where(EditionManager::TABLE_NAME . '.isbn = ?', $isbn);
					
		$result = $this->_db->fetchAll($select);
		return $this->_createCollection(self::OBJECT_NAME, $result);
	}
	
}